<template>
  <a-modal
    title="编辑学生"
    :width="600"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
<!--        <a-row :gutter="24">-->
<!--          <a-col :md="20" :sm="24">-->
<!--            <a-form-item-->
<!--              label="学生学号"-->
<!--              :labelCol="labelCol"-->
<!--              :wrapperCol="wrapperCol"-->
<!--            >-->
<!--              <a-input-->
<!--                v-decorator="['studentCode', {initialValue: student.studentCode, rules: [-->
<!--                  { required: true, message: '请输入登录账号', trigger: 'blur' }]}]"></a-input>-->
<!--            </a-form-item>-->
<!--          </a-col>-->
<!--        </a-row>-->
        <a-row :gutter="24">
          <a-col :md="20" :sm="24">
            <a-form-item
              label="学生姓名"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
            >
              <a-input
                v-decorator="['studentName', {initialValue: student.studentName, rules: [
                  {required: true, message: '请输入学生姓名', trigger: 'blur'}]}]"></a-input>
            </a-form-item>
          </a-col>
        </a-row>
<!--        <a-row :gutter="24">-->
<!--          <a-col :md="20" :sm="24">-->
<!--            <a-form-item-->
<!--              label="学生角色"-->
<!--              :labelCol="labelCol"-->
<!--              :wrapperCol="wrapperCol"-->
<!--            >-->
<!--              <a-select-->
<!--                v-decorator="['roleId', {initialValue: String(student.roleId), rules: [{required: true, message: '请选择角色'}]}]"-->
<!--                placeholder="请选择"-->
<!--                disabled>-->
<!--                <a-select-option v-for="role in roles" :key="role.id">{{ role.name }}</a-select-option>-->
<!--              </a-select>-->
<!--            </a-form-item>-->
<!--          </a-col>-->
<!--        </a-row>-->
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import { editStudent } from '@/api/basic/student'

export default {
  props: {
    roles: {
      type: Array,
      default () {
        return {}
      }
    }
  },
  data () {
    return {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      visible: false,
      confirmLoading: false,
      student: {},
      form: this.$form.createForm(this)
    }
  },

  methods: {
    edit (record) {
      this.visible = true
      this.student = record
    },
    handleSubmit () {
      const { form: { validateFields } } = this
      this.confirmLoading = true
      validateFields((errors, values) => {
        if (!errors) {
          editStudent(Object.assign(values, { 'studentId': this.student.studentId }))
            .then(() => {
              this.visible = false
              this.confirmLoading = false
              this.form.resetFields()
              this.$emit('ok')
            }).catch(err => {
            this.confirmLoading = false
            this.$message.error(err.result || '操作失败！')
          })
        } else {
          this.confirmLoading = false
        }
      })
    },
    handleCancel () {
      this.form.resetFields()
      this.visible = false
    }
  }
}
</script>
